package com.atguigu.daijia.driver.controller;


import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.driver.service.DriverInfoService;
import com.atguigu.daijia.model.entity.driver.DriverSet;
import com.atguigu.daijia.model.form.driver.DriverFaceModelForm;
import com.atguigu.daijia.model.form.driver.UpdateDriverAuthInfoForm;
import com.atguigu.daijia.model.vo.driver.DriverAuthInfoVo;
import com.atguigu.daijia.model.vo.driver.DriverInfoVo;
import com.atguigu.daijia.model.vo.driver.DriverLoginVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

;

@Slf4j
@Tag(name = "司机API接口管理")
@RestController
@RequestMapping(value="/driver/info")
@SuppressWarnings({"unchecked", "rawtypes"})
@RequiredArgsConstructor
public class DriverInfoController {

    private final DriverInfoService driverInfoService;

    /**
     * 司机端微信小程序授权登录
     * @param code
     * @return
     */
    @Operation(summary = "微信小程序授权登录")
    @GetMapping("/login/{code}")
    public Result<Long> login(@PathVariable("code") String code) {
        return Result.ok(driverInfoService.login(code));
    }

    /**
     * 获取登录司机的信息
     * @param driverId
     * @return
     */
    @Operation(summary = "获取登录司机的信息")
    @GetMapping("/getDriverLoginInfo/{driverId}")
    public Result<DriverLoginVo> getDriverLoginInfo(@PathVariable("driverId") Long driverId) {
        DriverLoginVo driverLoginInfo = driverInfoService.getDriverLoginInfo(driverId);
        return Result.ok(driverLoginInfo);
    }

    /**
     * 获取司机认证信息
     * @param driverId
     * @return
     */
    @Operation(summary = "获取司机认证信息")
    @GetMapping("/getDriverAuthInfo/{driverId}")
    public Result<DriverAuthInfoVo> getDriverAuthInfo(@PathVariable("driverId") Long driverId) {
        DriverAuthInfoVo driverAuthInfoVo = driverInfoService.getDriverAuthInfo(driverId);
        return Result.ok(driverAuthInfoVo);
    }

    /**
     * 更新司机认证信息
     * @param updateDriverAuthInfoForm 司机端小程序更新司机认证信息表单提交的数据
     * @return
     */
    @Operation(summary = "更新司机认证信息")
    @PostMapping("/updateDriverAuthInfo")
    public Result<Boolean> updateDriverAuthInfo(@RequestBody UpdateDriverAuthInfoForm updateDriverAuthInfoForm) {
        Boolean result = driverInfoService.updateDriverAuthInfo(updateDriverAuthInfoForm);
        return Result.ok(result);
    }

    /**
     * 创建司机人脸模型
     * @param driverFaceModelForm 司机人脸模型表单提交的数据
     * @return
     */
    @Operation(summary = "创建司机人脸模型")
    @PostMapping("/createDriverFaceModel")
    public Result<Boolean> createDriverFaceModel(@RequestBody DriverFaceModelForm driverFaceModelForm) {
        Boolean result = driverInfoService.createDriverFaceModel(driverFaceModelForm);
    	return Result.ok(result);
    }

    /**
     * 获取司机设置信息
     * @param driverId
     * @return
     */
    @Operation(summary = "获取司机设置信息")
    @GetMapping("/getDriverSet/{driverId}")
    public Result<DriverSet> getDriverSet(@PathVariable("driverId") Long driverId) {
        DriverSet driverSet = driverInfoService.getDriverSet(driverId);
        return Result.ok(driverSet);
    }

    /**
     * 判断司机当日是否进行过人脸识别
     * @param driverId
     * @return
     */
    @Operation(summary = "判断司机当日是否进行过人脸识别")
    @GetMapping("/isFaceRecognition/{driverId}")
    public Result<Boolean> isFaceRecognition(@PathVariable("driverId") Long driverId) {
        Boolean result = driverInfoService.isFaceRecognition(driverId);
        return Result.ok(result);
    }

    /**
     * 司机人脸识别
     * @param driverFaceModelForm
     * @return
     */
    @Operation(summary = "司机人脸识别")
    @PostMapping("/verifyDriverFace")
    public Result<Boolean> verifyDriverFace(@RequestBody DriverFaceModelForm driverFaceModelForm) {
        Boolean result = driverInfoService.verifyDriverFace(driverFaceModelForm);
        return Result.ok(result);
    }

    /**
     * 更新司机接单状态
     * @param driverId
     * @param status
     * @return
     */
    @Operation(summary = "更新司机接单状态")
    @GetMapping("/updateServiceStatus/{driverId}/{status}")
    public Result<Boolean> updateServiceStatus(@PathVariable("driverId") Long driverId, @PathVariable("status") Integer status) {
        Boolean result = driverInfoService.updateServiceStatus(driverId, status);
    	return Result.ok(result);
    }

    /**
     * 根据司机 ID 获取司机基本信息
     * @param driverId
     * @return
     */
    @Operation(summary = "根据司机 ID 获取司机基本信息")
    @GetMapping("/getDriverInfo/{driverId}")
    public Result<DriverInfoVo> getDriverInfo(@PathVariable("driverId") Long driverId) {
        DriverInfoVo driverInfoVO = driverInfoService.getDriverInfo(driverId);
        return Result.ok(driverInfoVO);
    }

    /**
     * 获取司机微信 OpenId
     * @param driverId
     * @return
     */
    @Operation(summary = "获取司机微信 OpenId")
    @GetMapping("/getDriverOpenId/{driverId}")
    public Result<String> getDriverOpenId(@PathVariable("driverId") Long driverId) {
        String openId = driverInfoService.getDriverOpenId(driverId);
        return Result.ok(openId);
    }
}

